﻿<%@ Page Title="" Language="C#" MasterPageFile="~/GUI/MasterPage.master" AutoEventWireup="true" CodeFile="UserManage.aspx.cs" Inherits="Home_UserManage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

    <script type="text/javascript">
        
        function confirmation(username) {
            var err = "<%=deletecf%>";
            var answer = confirm(err);
            if (answer) {
                window.location = "Delete.aspx?EditUser=" + username;
            }
        }
       </script>
    <script language = "Javascript">

        function echeck(str) {

            var at = "@"
            var dot = "."
            var lat = str.indexOf(at)
            var lstr = str.length
            var ldot = str.indexOf(dot)
            if (str.indexOf(at) == -1) {
                alert("Invalid E-mail ID")
                return false
            }

            if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr) {
                alert("Invalid E-mail ID")
                return false
            }

            if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr) {
                alert("Invalid E-mail ID")
                return false
            }

            if (str.indexOf(at, (lat + 1)) != -1) {
                alert("Invalid E-mail ID")
                return false
            }

            if (str.substring(lat - 1, lat) == dot || str.substring(lat + 1, lat + 2) == dot) {
                alert("Invalid E-mail ID")
                return false
            }

            if (str.indexOf(dot, (lat + 2)) == -1) {
                alert("Invalid E-mail ID")
                return false
            }

            if (str.indexOf(" ") != -1) {
                alert("Invalid E-mail ID")
                return false
            }

            return true
        }

        function ValidateForm() {
            var emailID = document.getElementById("txtMail");
            var user = document.getElementById("txtName");
            var pass = document.getElementById("txtPass");
            if (user.value == null || user.value == '') {
                alert("Please Enter your Username");
                user.focus();
                return false;
            }

            if (pass.value == null || pass.value == '') {
                alert("Please Enter your Password");
                pass.focus();
                return false;
            }

            if ((emailID.value == null) || (emailID.value == "")) {
                alert("Please Enter your Email ID")
                emailID.focus()
                return false
            }
            if (echeck(emailID.value) == false) {
                emailID.value = ""
                emailID.focus()
                return false
            }
            return true
        }
</script>
    <div class="First">
        <div class="IconTitle"><img src="../Images/icon_title.png"/></div>
        <div class="Title"><%= Language[title] %></div>
    </div>
    <div class="Second">
        <div class="BoxUser">
            <div class="Item1">
                <div class="ClassLabel"><%= Language["UserName"] %></div>
                <% if(isEdit) { %>
                    <input type="text" id="Text1" value="<%=userSelected.Account%>" name="txtName" disabled="disabled"/>
                <%} else{%>
                    <input type="text" id="txtName" value="<%=userSelected.Account%>" name="txtName" />
                <%} %>
                
            </div>
            <div class="Item1">
                <div class="ClassLabel"><%= Language["Password"] %></div>
                <input type="password" id="txtPass" value="" name="txtPass"/>
            </div>
            <div class="Item1">
                <div class="ClassLabel"><%= Language["Email"] %></div>
                <input type="text" id="txtMail" value="<%=userSelected.Mail%>" name="txtMail"/>
            </div>
            <div class="ItemRole">
                <div class="ClassLabel"><%= Language["Role"] %></div>                          
                <asp:DropDownList ID="comboRole" runat="server">
                </asp:DropDownList>            
            </div>
            <div class="Item2">
                <asp:Button Text="Create new user" CssClass="BtnAddNewCategory" ID="btn_create" runat="server" BorderStyle="None" Font-Size="Medium" Height="36px" Width="346px" OnClick="btn_create_Click" OnClientClick="return ValidateForm();"/>
            </div>
        </div>
    </div>
    <table class="TableCategories">
    <thead>
        <th><%= Language["UserName"] %></th>
        <th><%= Language["Role"] %></th>
        <th><%= Language["Active"] %></th>
        <th></th>
    </thead>
    <tbody>
        <% for (int i = 0; i < users.Count; i = i + 1)
           { %>
        <tr class="Even">
            <td><%=users[i].Account%></td>
            <td><%=GetRoleById((long)users[i].RoleID) %></td>
            <td>
                <input type="checkbox" <%=ConvertActive((bool)users[i].Active) %> />
            </td>
            <td class="Action">
                <a href="../Home/UserManage.aspx?EditUser=<%=users[i].Account %>"><%= Language["Edit"]%></a> 
                <a style="padding-left:35px; " href="#"  onclick="confirmation('<%=users[i].Account%>')"><%= Language["Delete"] %></a>
            </td>
        </tr>
        
        <%} %>
    </tbody>
</table>

</asp:Content>

